﻿using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
using System.Threading.Tasks;
using zhangmenren.IService;
using zhangmenren.Models;
using zhangmenren.Untils;
using zhangmenren.Models.Enums;
using System.Linq;

namespace zhangmenren.Controllers
{
    public class HomeController : Controller
	{
		private IBannerService _bannerService;

		private ICacheService _cacheService;

        private IWorksService worksService;

        private ICommentServic commentServic;

		public HomeController(ICommentServic _commentServic,IWorksService _worksService,IBannerService bannerService, ICacheService cacheService)
		{
            worksService = _worksService;
            _bannerService = bannerService;
			_cacheService = cacheService;
            commentServic = _commentServic;

        }

		public async Task<IActionResult> Index()
		{
            if (Request.Host.Value=="admin.dxzmr.com")
            {
                return Redirect("/admin/admin");
            }


            //var aaa =AliSMS.SendSMS("13007607662");
            ViewBag.Banner = await GetData.GetBanner(_bannerService, _cacheService, "IndexBanner",BannerType.INDEX);


            var ret = await worksService.Selelct(WorkType.ZMTJ, "",10);

            ViewBag.List = ret.ToList();

            var comments = await commentServic.Select();

            ViewBag.Commment = comments.Take(10).ToList();

            return View();
		}

		public IActionResult About()
		{
			ViewData["Message"] = "Your application description page.";

			return View();
		}

		public IActionResult Contact()
		{
			ViewData["Message"] = "Your contact page.";

			return View();
		}

		public IActionResult Privacy()
		{
			return View();
		}







		[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
		public IActionResult Error()
		{
			return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
		}
	}
}
